package com.dtw.ditouwang.ui.movement;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.ChallengeListBean;
import com.dtw.ditouwang.ui.OnItemClickListener;
import com.dtw.ditouwang.ui.more.CommentAdapter;

import java.util.List;

public class ChallengeAdapter extends RecyclerView.Adapter<ChallengeAdapter.Holder> {
    List<ChallengeListBean.DataBean> challengeList;
    OnItemClickListener onItemClickListener;

    public ChallengeAdapter(List<ChallengeListBean.DataBean> challengeList) {

        this.challengeList = challengeList;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){

        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_challenge_list, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        holder.textView.setText(challengeList.get(i).getName());
    }

    @Override
    public int getItemCount() {
        return challengeList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView textView;

        public Holder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text_text);
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickListener!=null){
                        onItemClickListener.onItemClick(0, getAdapterPosition(), 0);
                    }
                }
            });
        }
    }
}
